import tkinter as tk
def undofun():
    s,t=txt01.get(),txt02.get()
    ss,c,num='撤销过程：'+s,'',''
    for i in range(len(t)-1,-1,-1):
        ch=t[i]
        if ch .isalpha(): #判断是字母吗？
            c=ch+c
        elif ch .isdigit(): #判断是数字吗？
            num=ch+num
        else:
            n=int(num)
            if ch=="-" :
                s=s[:n-1]+c+s[n-1:]
            else:
                s=s[:n-1]+s[n+len(c)-1:]
            ss=ss+"→"+s
            c,num='',''
    text.set(ss)

win=tk.Tk()
win.title('模拟撤销')
win.geometry ('400x180')
text = tk.StringVar()

# 建组件
lb01=tk.Label(win,text="模拟撤销前字符串：")
lb02=tk.Label(win,text="历史记录：")
txt01=tk.Entry(win)
txt02=tk.Entry(win)
txt01.insert(0,'Bike')
txt02.insert(0,'+2i-3oo+4e')
btn=tk.Button(win,text="撤销",command=undofun)
text.set('撤销过程：')
lb03=tk.Label(win,textvariable=text)

#布局
lb01.grid(row=0,column=0,padx=10,pady=10)
lb02.grid(row=1,column=0)
txt01.grid(row=0,column=1)
txt02.grid(row=1,column=1)
btn.grid(row=2,column=1,sticky="ew")
lb03.grid(row=3,column=0,columnspan=3)

win.mainloop()